package com.water.component.nacos.config.junit;

import com.water.wfo.component.junit.BaseTest;
import com.water.wfo.component.util.SystemPropertiesUtil;
import org.junit.Assert;
import org.junit.BeforeClass;

import java.io.InputStream;
import java.util.Properties;

/**
 * packageName com.water.component.nacos.config.junit
 *
 * @author
 * @className BaseNacosTest(处以class为网)
 * @date 2025/3/13
 * @description T0D0
 */
public class BaseNacosTest extends BaseTest {
    /**
     * junit系统配置
     */
    protected static final Properties JUNIT_SYSTEM_PROPERTIES = new Properties();

    /**
     * 加载单元测试启动配置文件
     * @return
     */
    public static final void readSystemProperties() {
        try {
            InputStream resourceExtra = BaseNacosTest.class.getResourceAsStream("/system-config-wfo-extra.properties");
            if(null != resourceExtra) {
                JUNIT_SYSTEM_PROPERTIES.load(resourceExtra);
            }
        } catch (Exception e) {
            Assert.fail("单元测试配置system-config-wfo-extra.properties加载失败");
        }
        for(String key : JUNIT_SYSTEM_PROPERTIES.stringPropertyNames()){
            System.getProperties().setProperty(key, JUNIT_SYSTEM_PROPERTIES.getProperty(key));
        }
        SystemPropertiesUtil.setSystemProperties(JUNIT_SYSTEM_PROPERTIES);
    }

    /**
     * 下拉nacos配置文件
     * @throws
     */
    @BeforeClass
    public static void beforTest() {
        // 启动配置
        readSystemProperties();
    }
}
